<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

<ui:composition template="/WEB-INF/templates/BasicTemplate.xhtml">

	<ui:define name="content">
		<f:event type="preRenderView"
			listener="#{userController.beforeEdit}" />
			
			<div class="title ui-widget-header ui-corner-all">
			<h:panelGrid style="margin:auto;">
		EDITAR USUARIO
		</h:panelGrid>

		</div>
		<h:form id="formEdit">
			<h:panelGrid style="margin:auto;">

				<h:panelGrid style="margin:auto;text-align:center;">
					<p:messages id="messages"></p:messages>
				</h:panelGrid>

				<h:panelGrid columns="4">

					<p:outputLabel value="Nombres"></p:outputLabel>
					<p:inputText
						value="#{userController.userSelected.person.firstname}"
						id="firstname" style="width: 300px;" required="true"
						requiredMessage="Debe ingresar Nombres"></p:inputText>

					<p:outputLabel value="Documento de identidad"></p:outputLabel>
					<p:inputText id="userDocumentNumber"
						value="#{userController.userSelected.person.documentNumber}"
						required="true"
						requiredMessage="Debe ingresar documento de identidad"></p:inputText>



					<p:outputLabel value="Apellidos"></p:outputLabel>
					<p:inputText value="#{userController.userSelected.person.lastname}"
						id="lastname" style="width: 300px;" required="true"
						requiredMessage="Debe ingresar Apellidos"></p:inputText>

					<p:outputLabel value="Username"></p:outputLabel>
					<p:inputText value="#{userController.userSelected.username}"
						required="true" requiredMessage="Debe ingresar Username"></p:inputText>


					<p:outputLabel value="Departamento"></p:outputLabel>
					<p:selectOneMenu id="departments"
						value="#{userController.departmentSelected}">
						<f:selectItem itemValue="" itemLabel="Seleccione"></f:selectItem>
						<f:selectItems value="#{userController.departments}"></f:selectItems>
						<p:ajax listener="#{userController.searchSubDepartments}"
							update=":formEdit:subDepartments :formEdit:messages"></p:ajax>
					</p:selectOneMenu>


					<p:outputLabel value="Password"></p:outputLabel>
					<p:inputText value="#{userController.userSelected.password}"
						required="true" requiredMessage="Debe ingresar Password"></p:inputText>

					<p:outputLabel value="SubDepartamento"></p:outputLabel>
					<p:selectOneMenu id="subDepartments" required="true"
						requiredMessage="Debe seleccionar: Subdepartamento."
						value="#{userController.subDepartmentSelected}">
						<f:selectItem itemValue="" itemLabel="Seleccione"></f:selectItem>
						<f:selectItems value="#{userController.subDepartments}"></f:selectItems>
					</p:selectOneMenu>



					<p:outputLabel value="¿Activo?"></p:outputLabel>
					<p:selectOneMenu value="#{userController.userSelected.isActive}"
						required="true" requiredMessage="Debe seleccionar ¿Activo?">
						<f:selectItem itemValue="true" itemLabel="Si"></f:selectItem>
						<f:selectItem itemValue="false" itemLabel="No"></f:selectItem>
					</p:selectOneMenu>

					<p:outputLabel value="Permisos"></p:outputLabel>
					<p:selectManyCheckbox layout="grid" value="#{userController.permissionsSelected}" columns="2">
						<f:selectItems value="#{userController.permissions}"></f:selectItems>
					</p:selectManyCheckbox>
					<p:outputLabel value="Departamentos"></p:outputLabel>
					<p:selectManyCheckbox layout="grid" value="#{userController.departmentsSelected}" columns="2">
						<f:selectItems value="#{userController.departments}"></f:selectItems>
					</p:selectManyCheckbox>

				</h:panelGrid>

				<h:panelGrid style="margin:auto;text-align:center;">
					<p:commandButton action="#{userController.edit}" value="Editar"
						ajax="false">
					</p:commandButton>
				</h:panelGrid>
			</h:panelGrid>
		</h:form>
	</ui:define>

</ui:composition>
</html>
